package com.example.tabhostdemo;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

/**
 * 将Activity改为ActivityGroup，是为了获取LocalActivityManager
 */
public class MainActivity2 extends ActivityGroup {
	private TabHost tabHost;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main2);
		
		tabHost = (TabHost) findViewById(R.id.tabhost);
		tabHost.setup();
		
		tabHost.setup(getLocalActivityManager());
		
		TabSpec tabSpec1 = tabHost.newTabSpec("first");
		tabSpec1.setIndicator("first 第一个", getResources().getDrawable(R.drawable.first));
		tabSpec1.setContent(new Intent(MainActivity2.this, FirstActivity.class));
		tabHost.addTab(tabSpec1);
		TabSpec tabSpec2 = tabHost.newTabSpec("second");
		tabSpec2.setIndicator("second 第二个", getResources().getDrawable(R.drawable.second));
		tabSpec2.setContent(new Intent(MainActivity2.this, SecondActivity.class));
		tabHost.addTab(tabSpec2);
		TabSpec tabSpec3 = tabHost.newTabSpec("third");
		tabSpec3.setIndicator("third 第三个", getResources().getDrawable(R.drawable.third));
		tabSpec3.setContent(new Intent(MainActivity2.this, ThirdActivity.class));
		tabHost.addTab(tabSpec3);
		
	}
	
}
